<?php

namespace app\stock\controller\Manage;

use think\Controller;
use think\Db;

class Privatesea extends Controller
{
    // 模型
    protected $BusinessModel = null;

    public function __construct()
    {
        parent::__construct();

        $this->BusinessModel = model("Business.Business");
    }

    public function index()
    {
        $privateseaData = $this->BusinessModel->with(['source'])->whereNotNUll('adminid')->order('createtime DESC')->select();

        if (!$privateseaData) {
            $this->error('暂无数据');
        }

        $this->success('查询成功', null, $privateseaData);
    }

    public function info()
    {
        $busid = $this->request->param('busid', 0, 'trim');

        $Business = $this->BusinessModel->with(['source'])->find($busid);

        if (!$Business) {
            $this->error('用户不存在');
        }

        $this->success('返回数据成功', null, $Business);
    }

    public function del()
    {
        $busid = $this->request->param('busid', 0, 'trim');

        $adminid = $this->request->param('adminid', 0, 'trim');

        $Business = $this->BusinessModel->find($busid);

        if (!$Business) {
            $this->error('用户不存在');
        }

        $admin = model('Admin')->find($adminid);

        if (!$admin) {
            $this->error('管理员不存在');
        }

        if ($admin['status'] !== 'normal') {
            $this->error('当前账号已禁用');
        }

        $result = $this->BusinessModel->destroy($busid);

        if ($result === FALSE) {
            $this->error('删除失败');
        } else {
            $this->success('删除成功');
        }
    }
}
